<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <!-- 2. 引入vuejs -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>

  <body>
    <!-- 1. 准备容器 -->
    <div id="app">
      <!-- 4. 渲染数据 -->
      <h3>小黑的旅行</h3>
      <ul>
        <li  v-for="(item,index) in arr">
          <span>{{item}}</span>
          <button @click="del(index)">删除</button>
          <!-- <span>{{ item.author }}</span> -->
          <!-- 注册点击事件 →  通过 id 进行删除数组中的 对应项 -->
        </li>
        
        <button @click="move">生成</button> 
      </ul>
      
    </div>
    <script>
      // 3. 创建Vue实例
      const app = new Vue({
        el: "#app",
        data: {
            arr:[1,5,3],
          flag:true  
        },
       
        methods: {
          move() {
            let num = Math.floor(Math.random() * 20) + 1;
              this.arr.push(num);
          },
          del(index) {
        //    this.arr=this.arr.filter(arr=>arr.index!==index)
        this.arr.splice(index,1)
          },
        }
       
      });
    </script>
    <!-- this.booksList = this.booksList.filter(item => item.id !== id) -->
    
  </body>
</html>
